// 公告查看
package com.example.wuyeguanli.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.wuyeguanli.R;
import com.example.wuyeguanli.entiy.AnnouncementItem;
import com.example.wuyeguanli.tools.AnnouncementAdapter;

import java.util.ArrayList;
import java.util.List;

public class AnnouncementActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private AnnouncementAdapter announcementAdapter;
    private List<AnnouncementItem> itemList;
    private Button btnBack;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_announcement);

        //隐藏标题栏
        if(getSupportActionBar() != null){
            getSupportActionBar().hide();
        }

        btnBack = findViewById(R.id.btn_back);
        btnBack.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // 跳转到主页面
                finish();
            }
        });

        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setHasFixedSize(true); // 提高性能

        // 1. 设置布局管理器
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        // 2. 准备数据
        itemList = new ArrayList<>();
        itemList.add(new AnnouncementItem("热烈欢迎总书记莅临社区", "2025/6/4", "总书记来到社区进行观光与指导工作", R.drawable.img_welcome));
        itemList.add(new AnnouncementItem("社区停水通知", "2025/6/8", "本社区将于明天停水24小时", R.drawable.img_water));
        itemList.add(new AnnouncementItem("社区食堂整顿公告", "2025/6/9", "社区食堂将于9月重新开放", R.drawable.img_restaurant));
        itemList.add(new AnnouncementItem("第一届彩霞杯大赛圆满落幕", "2025/6/10", "彩霞杯秧歌大赛于昨日圆满落幕", R.drawable.img_yangge));
        itemList.add(new AnnouncementItem("居委会成员选举结果公示", "2025/6/15", "以下是居委会成员换届选举结果：", R.drawable.img_xuanju));

        // 3. 创建并设置适配器
        announcementAdapter = new AnnouncementAdapter(itemList);
        recyclerView.setAdapter(announcementAdapter);
    }
}
